import axios from 'axios';
import { Session } from '/@/utils/storage';

const baseUrl = import.meta.env.VITE_API_BASE_URL;
const uploadApi = (import.meta.env.VITE_API_BASE_URL + "/common/upload");

export function commonUpload(file) {
    const formData = new FormData();
    formData.append('file', file);
    const res = axios.post(uploadApi, formData, {
        // 因为我们上传了图片,因此需要单独执行请求头的Content-Type
        headers: {
            // 表示上传的是文件,而不是普通的表单数据
            'Content-Type': 'multipart/form-data',
            Authorization: "Bearer " + Session.getToken()
        }
    })
    return res;
}

